/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.controlstudent.datos;


import com.controlstudent.entidades.Citacion;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Batkev
 */
public class CitacionDAO {
     private static CitacionDAO instance = null;

    private CitacionDAO() {
    }

    public static CitacionDAO getInstance() {
        if (instance == null) {
            instance = new CitacionDAO();
        }
        return instance;
    }
    
     public ArrayList<Citacion> citacionxalumno(int id_alumn) {
        ArrayList<Citacion> citaciones = null;
        Connection cn = null;

        String sql = "select cita_id,cita_asunto,cita_fec,cita_lugar,cita_desc from citacion c inner join citacion_alumno ca on ca.id_citacion=c.cita_id  where id_alumno=? and cita_fec>GETDATE();";
                

        try {
            citaciones=new ArrayList<>();
            cn = ConnectionManager.getConnection();
            PreparedStatement ps = cn.prepareStatement(sql);
            ps.setInt(1, id_alumn);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Citacion a = new Citacion();
                a.setCita_id(rs.getInt(("cita_id")));
                a.setCita_aunto(rs.getString("cita_asunto"));
                a.setCita_fec(rs.getString("cita_fec"));
                a.setCita_lugar(rs.getString("cita_lugar"));
                a.setCita_desc(rs.getString("cita_desc"));
               
                citaciones.add(a);
            }
        } catch (Exception e) {
        } finally {
            try {
                cn.close();
            } catch (SQLException ex) {
            }
        }
        return citaciones;
    }
    
    
    
}
